#ifndef DB_MANAGER_H
#define DB_MANAGER_H

#include <mysql/mysql.h>
#include <string>
#include <vector>
#include <map>

class DBManager {
private:
    MYSQL* connection;//数据库连接
    static DBManager* instance;//获取单例对象
    
    DBManager();
    bool createTables();
    bool insertTestData();
    
public:
    static DBManager& getInstance();
    ~DBManager();
    
    bool initialize(const std::string& host, const std::string& database, 
                   const std::string& username, const std::string& password);
    bool executeQuery(const std::string& query);
    std::vector<std::map<std::string, std::string>> executeSelectQuery(const std::string& query);
    unsigned long long getLastInsertId();
    unsigned long long getAffectedRows();
    std::string escapeString(const std::string& str);
    void close();
    bool isConnected() const;
};

#endif // DB_MANAGER_H 